var mySwiper;
var myIscroll=new IScroll('#wrapper',{
	click:true,
	tap:true,
})
$(function(){
//	获取banner
	$('.swiper-wrapper').html('');
	var baseUrl="http://datainfo.duapp.com/shopdata/";
	var getbannerURL=baseUrl+"getBanner.php";
	$.ajax({
		type:"get",
		url:getbannerURL,
		dataType:"jsonp",
		success:function(data){
			$('.swiper-wrapper').html('');
			var bannerHtml="";
			for(var i=0;i<data.length;i++){
				var str=JSON.parse(data[i].goodsBenUrl);
				bannerHtml+="<div class='swiper-slide'><img src='"+str[0]+"' /></div>"
			}
			$('.swiper-wrapper').append(bannerHtml);
			mySwiper=new Swiper('.swiper-container',{
				pagination:'.swiper-pagination',
			})	
		}
	});
//	获取商品
	var getGoodsURL=baseUrl+"getGoods.php";
		$.ajax({
			type:"get",
			url:getGoodsURL,
			dataType:"jsonp",
			success:function(data){
				var goodsHTML=""
				for(var j=0;j<data.length;j++){
					goodsHTML+="<li class='item'  goodsID='"+data[j].goodsID+"'><div class='pri-left'><img src='"+data[j].goodsListImg+"' /></div><div class='pri-right'><p>"+
					data[j].goodsName+"</p><div class='pr-box'><div class='pb-left'><span>￥"+
					data[j].price*data[j].discount/10+"</span><span>￥"+
					data[j].price+"</span><p>"+data[j].discount+"折</p></div><div class='pb-right'><img class='carimg' src='img/index-cat.png' /></div></div></div></li>"
				}
				
				$("#scroller ul").append(goodsHTML);
				myIscroll.refresh();
				$('#scroller ul').on('click','.carimg',function(){
					var goodsID=$(this).parents('.item').attr('goodsID');
					$.ajax({
						type:'get',
						url:'http://datainfo.duapp.com/shopdata/updatecar.php',
						data:{userID:sessionStorage.getItem('auto')||localStorage.getItem('auto'),
								goodsID:goodsID},
						success:function(data){
							console.log(data)
							if(data==1){
								alert('添加购物车成功');
							}
							if(data==0){
								alert('请先登录才能购物哦')
								window.open("login.html")
							}
						}
					})
				})
				$('.pri-left img').click(function(){
					var goodsID=$(this).parents('.item').attr('goodsID');
					localStorage.setItem('goodsID',goodsID);
					window.location.href="detaild.html";
			})
			}
})
	
	
	$('.foot').click(function(){
		var k=$('.foot').index($(this));
		$('.foot').removeClass('foots');
		$('.foot').eq(k).addClass('foots');
	})
})
